﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Northwind.NET.FE.Forms
{
    public partial class CustomerOrdersForm : Form
    {
        public CustomerOrdersForm()
        {
            InitializeComponent();
        }

        private void customerBindingNavigatorSaveItem_Click(object sender, EventArgs e)
        {
            this.Validate();
            this.customerBindingSource.EndEdit();
            this.tableAdapterManager.UpdateAll(this.customerOrdersFormDataSet);

        }

        private void CustomerOrdersForm_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'customerOrdersFormDataSet.CustomerOrdersProducts' table. You can move, or remove it, as needed.
            this.customerOrdersProductsTableAdapter.Fill(this.customerOrdersFormDataSet.CustomerOrdersProducts);
            // TODO: This line of code loads data into the 'customerOrdersFormDataSet.Order' table. You can move, or remove it, as needed.
            this.orderTableAdapter.Fill(this.customerOrdersFormDataSet.Order);
            // TODO: This line of code loads data into the 'customerOrdersFormDataSet.Customer' table. You can move, or remove it, as needed.
            this.customerTableAdapter.Fill(this.customerOrdersFormDataSet.Customer);

        }

        private void orderDataGridView_RowEnter(object sender, DataGridViewCellEventArgs e)
        {
            const int orderIdCellIndex = 0;
            DataGridViewRow row = orderDataGridView.Rows[e.RowIndex];
            int orderId = (int)row.Cells[orderIdCellIndex].Value ;
            string filter = string.Format("OrderId = {0}", orderId); 
            customerOrdersProductsBindingSource.Filter = filter;            
        }
    }
}
